import { defineStore } from "pinia";
import { Position } from "../composables/usePosition";
import { reactive } from "vue";

export enum MapTile {
    WALL = 1,
    FLOOR = 2,
}

export type Map = MapTile[][]

export const useMapStore = defineStore('mapStore',() => {
    let map = reactive<Map>([])

    function setupMap(newMap:Map) {
        // 从索引0开始，删除所有，返回空数组
        map.splice(0,map.length,...newMap)
    }

    function isWall(position:Position) {
        const { map } = useMapStore()   
        return map[position.y][position.x] === MapTile.WALL
    }

    return {
        map,
        setupMap,
        isWall
    }
})